<template>
	<view class="container">
		<!-- Header -->
		<view class="header">
			<view class="back-button"></view>
			<text class="title">{{orderList.cheService.name}}</text>
			<view class="more-options"></view>
		</view>

		<!-- 服务评价 -->
		<view class="section">
			<text class="section-title">服务评价</text>
			<view class="service-box">
				<image class="service-image" src="https://via.placeholder.com/150"></image>
				<view class="service-info">
					<text class="service-title">{{orderList.cheShop.name}}</text>
					<view class="rating">
						<text v-for="index in 5" :key="index" class="star">☆</text>
					</view>
					<input type="text" v-model="star" placeholder="请输入星级" />
				</view>
			</view>
		</view>

		<!-- 评语 -->
		<view class="section">
			<text class="section-title">评语 (0-299字)</text>
			<textarea class="comment-box" placeholder="请留下您宝贵的意见和建议……" maxlength="299" v-model="commit"></textarea>
			<p>{{ment}}</p>
		</view>

		<!-- 照片 -->
		<view class="section">
			<text class="section-title">照片 (选填)</text>
			<view class="photo-upload">
				<view class="upload-button">
					<text>+</text>
					<text class="upload-text">上传照片</text>
				</view>
			</view>
		</view>

		<!-- 提交按钮 -->
		<button class="submit-button" @click="tjpj()">提交</button>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				// 可以在此处定义数据变量
				cheOrder: {
					id: '',
					state: ''
				},
				star: '',
				id: '',
				orderList: {},
				commit: '',
				evaluate: {
					userId: '',
					orderId: '',
					comments: '',
					star: '',
					commentTime: ''
				}
			};
		},
		onLoad: function(opt) {
			this.id = opt.id;
			console.log(this.id)
			this.getOrder();
		},
		methods: {
			getOrder() {
				let that = this;
				this.$http({
					url: `/api/management/management/${that.id}`,
					method: 'GET',
					success(res) {
						// console.log(res)
						that.orderList = res.data.data
						console.log(that.orderList)
					}
				})
			},
			tjpj() {
				let that = this;

				// 设置评价对象的属性
				this.evaluate.userId = this.orderList.cheUser.id;
				this.evaluate.orderId = this.orderList.id;
				this.evaluate.comments = this.commit;
				this.evaluate.star = this.star;

				// 获取当前时间并设置为 commentTime
				const currentTime = new Date().toISOString(); // ISO 格式
				this.evaluate.commentTime = currentTime;

				// 发送评价数据
				this.$http({
					url: '/api/orders/orders',
					data: that.evaluate,
					method: 'POST',
					success(res) {
						console.log(res);
					}
				});

				// 修改订单状态
				that.cheOrder.id = that.id;
				that.cheOrder.state = 5
				this.$http({
					url: '/api/management/management',
					data: that.cheOrder,
					method: 'PUT',
					success(res) {
						console.log(res)
					}
				})
			}



		}
	};
</script>


<style>
	/* 通用样式 */
	.container {
		display: flex;
		flex-direction: column;
		background-color: #f5f5f5;
		height: 100vh;
		padding: 10px;
	}

	/* Header 样式 */
	.header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #007aff;
		height: 50px;
		padding: 0 15px;
		color: #fff;
	}

	.title {
		font-size: 18px;
		font-weight: bold;
	}

	/* Section 通用样式 */
	.section {
		margin-top: 15px;
		background-color: #fff;
		padding: 10px;
		border-radius: 8px;
	}

	.section-title {
		font-size: 14px;
		margin-bottom: 10px;
	}

	/* 服务评价样式 */
	.service-box {
		display: flex;
		align-items: center;
	}

	.service-image {
		width: 60px;
		height: 60px;
		border-radius: 8px;
		margin-right: 10px;
	}

	.service-info {
		flex: 1;
	}

	.service-title {
		font-size: 16px;
		margin-bottom: 8px;
	}

	.rating {
		display: flex;
	}

	.star {
		font-size: 20px;
		color: #cccccc;
		margin-right: 5px;
	}

	/* 评语样式 */
	.comment-box {
		width: 100%;
		height: 100px;
		border: 1px solid #e0e0e0;
		border-radius: 8px;
		padding: 10px;
		font-size: 14px;
		line-height: 1.5;
		resize: none;
	}

	/* 照片上传样式 */
	.photo-upload {
		display: flex;
		align-items: center;
	}

	.upload-button {
		width: 80px;
		height: 80px;
		border: 1px dashed #ccc;
		border-radius: 8px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.upload-button text {
		font-size: 24px;
		color: #ccc;
	}

	.upload-text {
		font-size: 12px;
		color: #666;
		margin-top: 5px;
	}

	/* 提交按钮样式 */
	.submit-button {
		background-color: #007aff;
		color: #fff;
		font-size: 16px;
		font-weight: bold;
		text-align: center;
		padding: 10px 0;
		border-radius: 8px;
		margin: 20px 0;
	}
</style>